package com.pro.service.imple;

import com.pro.mapper.JsGoodsCategroyMapper;
import com.pro.pojo.JsCourseClass;
import com.pro.pojo.JsGoodsCategroy;
import com.pro.service.JsGoodsCategroyService;
import com.pro.utils.GuavaUtil;
import com.pro.utils.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.ExecutionException;

/**
 * @author cyj
 * @date 2022.1.11$ 9.24$
 * @content :
 */
@Service
public class JsGoodsCategroyServiceImple implements JsGoodsCategroyService {

    @Autowired
    private JsGoodsCategroyMapper mapper;

    @Autowired
    private RedisCache redisCache;

    @Override
    public List<JsGoodsCategroy> getTree() {
        List<JsGoodsCategroy> JsGoodsClass = redisCache.getCacheList("JsGoodsClass");
        if (!JsGoodsClass.isEmpty()){
            return JsGoodsClass;
        }
        List<JsGoodsCategroy> productCategroys = mapper.getTree();
        JsGoodsCategroy jsProductCategroy = new JsGoodsCategroy();
        jsProductCategroy.setCategroyId(0);
        jsProductCategroy.setParentId(-1);
        jsProductCategroy.setTitle("选择分类类型");
        productCategroys.add(jsProductCategroy);
        redisCache.setCacheList("JsGoodsClass",productCategroys);
        return productCategroys;
    }

    /*删除一个节点  22.1.11   11.44  CYJ*/
    @Override
    public Boolean delGoodsCategroy(Integer categroyId) {
        Boolean flag = mapper.delGoodsCategroy(categroyId);
        if (flag){
            redisCache.deleteObject("JsGoodsClass");
        }
        return flag;
    }

    /*编辑一个节点  22.1.11   13.34  CYJ*/
    @Override
    public Boolean updateGoodsCategroy(JsGoodsCategroy jsGoodsCategroy) {
        Boolean flag = mapper.updateGoodsCategroy(jsGoodsCategroy);
        if (flag){
            redisCache.deleteObject("JsGoodsClass");
        }
        return flag;
    }

    /*新增一个节点  22.1.11   15.11  CYJ*/
    @Override
    public Boolean addGoodsCategroy(JsGoodsCategroy jsGoodsCategroy) {
        Boolean flag = mapper.addGoodsCategroy(jsGoodsCategroy);
        if (flag){
            redisCache.deleteObject("JsGoodsClass");
        }
        return flag;
    }
}
